package com.yegs.jltqc.controller;

import com.yegs.jltqc.TO.NamePageQuery;
import com.yegs.jltqc.VO.OutCome;
import com.yegs.jltqc.VO.QcProduce;
import com.yegs.jltqc.config.Msg;
import com.yegs.jltqc.service.OutComeService;
import com.yegs.jltqc.service.QcProduceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/qcProduce")
public class QcProduceController {

    @Autowired
    private QcProduceService qcProduceService;

    @PostMapping("/save")
    public Msg save(@RequestBody QcProduce qcProduce){
        try{
            return Msg.success("data", qcProduceService.save(qcProduce));
        }catch (Exception e){
            return Msg.error(e.getMessage());
        }
    }

    @GetMapping("/list")
    public Msg list(){
        return Msg.success("list",qcProduceService.list());
    }

    @GetMapping("/get")
    public Msg get(@RequestParam Long id){
        QcProduce qcProduce = qcProduceService.get(id);
        return Msg.success("data",qcProduce);
    }
    @GetMapping("/generateWorkflow")
    public Msg generateWorkflow(@RequestParam Long id){
        try {
            qcProduceService.generateWorkflow(id);
            return Msg.success("生成审批流成功");
        }catch (Exception e){
            return Msg.error(e.getMessage());
        }
    }

    @GetMapping("/del")
    public Msg del(@RequestParam Long id){
        qcProduceService.del(id);
        return Msg.success();
    }
    @PostMapping("/query")
    public Msg query(@RequestBody NamePageQuery query){
        return Msg.success("page",qcProduceService.query(query));
    }

    @GetMapping("/getLast")
    public Msg getLast(@RequestParam(required = false) Long id){
        return Msg.success("data",qcProduceService.getLast(id));
    }
    @GetMapping("/getNext")
    public Msg getNext(@RequestParam(required = false) Long id){
        return Msg.success("data",qcProduceService.getNext(id));
    }






}
